Skip to content

Conversation

@dabrt
Copy link
Contributor

@dabrt dabrt commented Nov 6, 2025

Question Answer
JIRA Ticket IBX-10885
Versions 4.6, 5.0
Edition all

Document Content Type search API

Checklist

  • Text renders correctly
  • Text has been checked with vale
  • Description metadata is up to date
  • Code samples are working
  • PHP code samples have been fixed with PHP CS fixer
  • Added link to this PR in relevant JIRA ticket or code PR

@github-actions
Copy link

github-actions bot commented Nov 6, 2025

@dabrt dabrt requested a review from barw4 November 7, 2025 12:30
@dabrt dabrt requested a review from barw4 November 17, 2025 09:06
@dabrt dabrt requested a review from barw4 November 17, 2025 10:17
@dabrt dabrt requested a review from barw4 November 17, 2025 10:36
Copy link
Contributor

@mnocon mnocon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Just a couple of suggestions from me

Comment on lines +14 to +17
#[AsCommand(
name: 'doc:find_content_types',
description: 'Lists content types that match specific criteria.'
)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Friendly reminder that this will not work on 4.6 - and needs to be downgraded (I can help with that if needed).

In general it's easier to write code for 4.6 and then update it to v5 with Rector - we don't have Rector downgrades configured (if they are doable at all)

@dabrt dabrt requested a review from mnocon November 18, 2025 14:03
@dabrt
Copy link
Contributor Author

dabrt commented Nov 18, 2025

@mnocon I made the changes you suggested but RTD is down, so no way to see it apart from a local build.
I'll happily rely on your expertise when it comes to adopting the code samole.

@github-actions
Copy link

code_samples/ change report

Before (on target branch)After (in current PR)

code_samples/api/public_php_api/src/Command/FindContentTypeCommand.php


code_samples/api/public_php_api/src/Command/FindContentTypeCommand.php

docs/content_management/content_api/managing_content.md@180:```php hl_lines="28-38"
docs/content_management/content_api/managing_content.md@181:[[= include_file('code_samples/api/public_php_api/src/Command/FindContentTypeCommand.php') =]]
docs/content_management/content_api/managing_content.md@182:```

001⫶<?php declare(strict_types=1);
002⫶
003⫶namespace App\Command;
004⫶
005⫶use Ibexa\Contracts\Core\Repository\ContentTypeService;
006⫶use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\ContentTypeQuery;
007⫶use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\Criterion;
008⫶use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\SortClause;
009⫶use Symfony\Component\Console\Attribute\AsCommand;
010⫶use Symfony\Component\Console\Command\Command;
011⫶use Symfony\Component\Console\Input\InputInterface;
012⫶use Symfony\Component\Console\Output\OutputInterface;
013⫶
014⫶#[AsCommand(
015⫶ name: 'doc:find_content_types',
016⫶ description: 'Lists content types that match specific criteria.'
017⫶)]
018⫶class FindContentTypeCommand extends Command
019⫶{
020⫶ public function __construct(private readonly ContentTypeService $contentTypeService)
021⫶ {
022⫶ parent::__construct();
023⫶ }
024⫶
025⫶ protected function execute(InputInterface $input, OutputInterface $output): int
026⫶ {
027⫶ // Find content types from the "Content" group that contains a specific field definition (in this case, a "Body" field).
028❇️ $query = new ContentTypeQuery(
029❇️ new Criterion\LogicalAnd([
030❇️ new Criterion\ContentTypeGroupId([1]),
031❇️ new Criterion\ContainsFieldDefinitionId([121]),
032❇️ ]),
033❇️ [
034❇️ new SortClause\Id(),
035❇️ new SortClause\Identifier(),
036❇️ new SortClause\Name(),
037❇️ ]
038❇️ );
039⫶
040⫶ $searchResult = $this->contentTypeService->findContentTypes($query);
041⫶
042⫶ $output->writeln('Found ' . $searchResult->getTotalCount() . ' content type(s):');
043⫶
044⫶ foreach ($searchResult->getContentTypes() as $contentType) {
045⫶ $output->writeln(sprintf(
046⫶ '- [%d] %s (identifier: %s)',
047⫶ $contentType->id,
048⫶ $contentType->getName(),
049⫶ $contentType->identifier
050⫶ ));
051⫶ }
052⫶
053⫶ return Command::SUCCESS;
054⫶ }
055⫶}

docs/search/content_type_search_reference/content_type_criteria.md@24:```php hl_lines="29-31"
docs/search/content_type_search_reference/content_type_criteria.md@25:[[= include_file('code_samples/api/public_php_api/src/Command/FindContentTypeCommand.php') =]]
docs/search/content_type_search_reference/content_type_criteria.md@26:```

001⫶<?php declare(strict_types=1);
002⫶
003⫶namespace App\Command;
004⫶
005⫶use Ibexa\Contracts\Core\Repository\ContentTypeService;
006⫶use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\ContentTypeQuery;
007⫶use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\Criterion;
008⫶use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\SortClause;
009⫶use Symfony\Component\Console\Attribute\AsCommand;
010⫶use Symfony\Component\Console\Command\Command;
011⫶use Symfony\Component\Console\Input\InputInterface;
012⫶use Symfony\Component\Console\Output\OutputInterface;
013⫶
014⫶#[AsCommand(
015⫶ name: 'doc:find_content_types',
016⫶ description: 'Lists content types that match specific criteria.'
017⫶)]
018⫶class FindContentTypeCommand extends Command
019⫶{
020⫶ public function __construct(private readonly ContentTypeService $contentTypeService)
021⫶ {
022⫶ parent::__construct();
023⫶ }
024⫶
025⫶ protected function execute(InputInterface $input, OutputInterface $output): int
026⫶ {
027⫶ // Find content types from the "Content" group that contains a specific field definition (in this case, a "Body" field).
028⫶ $query = new ContentTypeQuery(
029❇️ new Criterion\LogicalAnd([
030❇️ new Criterion\ContentTypeGroupId([1]),
031❇️ new Criterion\ContainsFieldDefinitionId([121]),
032⫶ ]),
033⫶ [
034⫶ new SortClause\Id(),
035⫶ new SortClause\Identifier(),
036⫶ new SortClause\Name(),
037⫶ ]
038⫶ );
039⫶
040⫶ $searchResult = $this->contentTypeService->findContentTypes($query);
041⫶
042⫶ $output->writeln('Found ' . $searchResult->getTotalCount() . ' content type(s):');
043⫶
044⫶ foreach ($searchResult->getContentTypes() as $contentType) {
045⫶ $output->writeln(sprintf(
046⫶ '- [%d] %s (identifier: %s)',
047⫶ $contentType->id,
048⫶ $contentType->getName(),
049⫶ $contentType->identifier
050⫶ ));
051⫶ }
052⫶
053⫶ return Command::SUCCESS;
054⫶ }
055⫶}

docs/search/content_type_search_reference/content_type_sort_clauses.md@22:```php hl_lines="34-36"
docs/search/content_type_search_reference/content_type_sort_clauses.md@23:[[= include_file('code_samples/api/public_php_api/src/Command/FindContentTypeCommand.php') =]]
docs/search/content_type_search_reference/content_type_sort_clauses.md@24:```

001⫶<?php declare(strict_types=1);
002⫶
003⫶namespace App\Command;
004⫶
005⫶use Ibexa\Contracts\Core\Repository\ContentTypeService;
006⫶use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\ContentTypeQuery;
007⫶use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\Criterion;
008⫶use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\SortClause;
009⫶use Symfony\Component\Console\Attribute\AsCommand;
010⫶use Symfony\Component\Console\Command\Command;
011⫶use Symfony\Component\Console\Input\InputInterface;
012⫶use Symfony\Component\Console\Output\OutputInterface;
013⫶
014⫶#[AsCommand(
015⫶ name: 'doc:find_content_types',
016⫶ description: 'Lists content types that match specific criteria.'
017⫶)]
018⫶class FindContentTypeCommand extends Command
019⫶{
020⫶ public function __construct(private readonly ContentTypeService $contentTypeService)
021⫶ {
022⫶ parent::__construct();
023⫶ }
024⫶
025⫶ protected function execute(InputInterface $input, OutputInterface $output): int
026⫶ {
027⫶ // Find content types from the "Content" group that contains a specific field definition (in this case, a "Body" field).
028⫶ $query = new ContentTypeQuery(
029⫶ new Criterion\LogicalAnd([
030⫶ new Criterion\ContentTypeGroupId([1]),
031⫶ new Criterion\ContainsFieldDefinitionId([121]),
032⫶ ]),
033⫶ [
034❇️ new SortClause\Id(),
035❇️ new SortClause\Identifier(),
036❇️ new SortClause\Name(),
037⫶ ]
038⫶ );
039⫶
040⫶ $searchResult = $this->contentTypeService->findContentTypes($query);
041⫶
042⫶ $output->writeln('Found ' . $searchResult->getTotalCount() . ' content type(s):');
043⫶
044⫶ foreach ($searchResult->getContentTypes() as $contentType) {
045⫶ $output->writeln(sprintf(
046⫶ '- [%d] %s (identifier: %s)',
047⫶ $contentType->id,
048⫶ $contentType->getName(),
049⫶ $contentType->identifier
050⫶ ));
051⫶ }
052⫶
053⫶ return Command::SUCCESS;
054⫶ }
055⫶}

Download colorized diff

Copy link
Contributor

@mnocon mnocon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@dabrt dabrt merged commit 70276ed into 5.0 Nov 19, 2025
6 of 7 checks passed
@dabrt dabrt deleted the IBX-10885 branch November 19, 2025 08:38
dabrt added a commit that referenced this pull request Nov 19, 2025
* IBX-10885: Document Content Type search API

---------

Co-authored-by: dabrt <dabrt@users.noreply.github.com>
Co-authored-by: Bartek Wajda <bartlomiej.wajda@ibexa.co>
dabrt added a commit that referenced this pull request Nov 19, 2025
* IBX-10885: Document Content Type search API

---------

Co-Authored-By: dabrt <dabrt@users.noreply.github.com>
Co-Authored-By: Bartek Wajda <bartlomiej.wajda@ibexa.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants